package kr.ac.kaist.savehearts.status;

import java.util.ArrayList;

import kr.ac.kaist.savehearts.auth.UserInfo;
import android.content.Context;

public class UserStatusUpdater {
	private static UserStatusUpdater _instance;
	public static UserStatusUpdater getInstance() {
		if ( _instance == null ) _instance = new UserStatusUpdater();
		return _instance;
	}
	
	private static final String TAG = UserStatusUpdater.class.getSimpleName();
	
	private ArrayList<UserInfo> lastNeighborSet;
	public ArrayList<UserInfo> getLastNeighborSet() { return this.lastNeighborSet; }
	protected void setLastNeighborSet(ArrayList<UserInfo> neighborSet) {
		this.lastNeighborSet = neighborSet;
	}
	
	private int lastUpdateTime;
	public int getLastUpdateTime() { return this.lastUpdateTime; }
	protected void setLastUpdateTime(int lastUpdateTime) { this.lastUpdateTime = lastUpdateTime; }
	
	public UserStatusUpdater() { }
	
	public void requestGetNeighbors(String email, double longitude, double latitude,
			Context context, StatusUpdateListener listener) {
		new RequestGetNeighborsTask(email, longitude, latitude, context, listener).execute();
	}
	
	public void requestLocationUpdate(String email, double longitude, double latitude,
			Context context, StatusUpdateListener listener) {
		new RequestLocationUpdateTask(email, longitude, latitude, context, listener).execute();
	}
	
	public void requestDeleteUser(String email, String password, 
			Context context, StatusUpdateListener listener) {
		new RequestDeleteUserTask(email, password, context, listener).execute();
	}
	
	/**
	 * requestModify() sends HTTP POST request to the server to modify current user's information.
	 @param firstName Firstname of the user
	 * @param lastName Lastname of the user
	 * @param email E-mail address of the user (not null)
	 * @param password Password of the user's account
	 * @param phoneNumber Phone number of the user
	 * @param context android.content.Context object or Activity to create progress dialog
	 * @param listener kr.ac.kaist.cds.savehearts.StatusUpdateListener to receive response from the server
	 */
	public void requestModifyUser(String firstName, String lastName, String email,
			String password, String phoneNumber, Context context, StatusUpdateListener listener) {
		new RequestModifyUserTask(firstName, lastName, email, password, phoneNumber, context, listener ).execute();
	}
	
	/**
	 * 
	 * @param email E-mail of the user required for authentication
	 * @param password Password of the user's account required for authentication
	 * @param context android.content.Context object or Activity to create progress dialog
	 * @param listener kr.ac.kaist.cds.savehearts.StatusUpdateListener to receive response from the server
	 */
	public void requestLogin(String email, String password, Context context, StatusUpdateListener listener) {
		new RequestLoginTask(email,	password, context, listener).execute();
	}
	
	/**
	 * requestJoin() sends HTTP POST request to the server to sign up current user.
	 * @param firstName Firstname of the user
	 * @param lastName Lastname of the user
	 * @param email E-mail address of the user (not null)
	 * @param password Password of the user's account
	 * @param phoneNumber Phone number of the user
	 * @param context android.content.Context object or Activity to create progress dialog
	 * @param listener kr.ac.kaist.cds.savehearts.StatusUpdateListener to receive response from the server
	 */
	public void requestJoin(String firstName, String lastName, String email,
						String password, String phoneNumber, Context context, StatusUpdateListener listener) {
		new RequestJoinTask(firstName, lastName, email,
				password, phoneNumber, context, listener).execute();
	}
}
